import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-07-01
 * Time：10:33
 */
public class RedisDemoStr {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        try(Jedis jedis = jedisPool.getResource()) {
            test4(jedis);
        }
    }

    public static void test4(Jedis jedis) {
        System.out.println("incr/decr");
        jedis.flushDB();

        jedis.set("key", "100");
        long result = jedis.incr("key");
        System.out.println(result);

        long result2 = jedis.decr("key");
        System.out.println(result2);  
    }
    private static void test3(Jedis jedis) {
        System.out.println("append");
        jedis.flushDB();

        jedis.set("key", "abcdefgh");
        jedis.append("key", "ijk");

        String val = jedis.get("key");
        System.out.println(val);
    }

    private static void test2(Jedis jedis) {
        System.out.println("setrange/getrange");
        jedis.flushDB();

        jedis.set("key", "abcdefgh");
        String subKey = jedis.getrange("key", 2, 4);
        System.out.println(subKey);

        jedis.setrange("key", 2, "xyz");
        String key = jedis.get("key");
        System.out.println(key);
    }

    private static void test1(Jedis jedis) {
        System.out.println("mset/mget");
        jedis.mset("key", "111", "key2", "222", "key3", "333");
        List<String> vals = jedis.mget("key", "key2", "key100", "key3");
        System.out.println(vals);
    }
}
